# load packages and data
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.0      ✔ stringr 1.4.1 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(plotly)
## Warning: 程辑包'plotly'是用R版本4.2.2 来建造的
## 
## 载入程辑包:'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
load("E:/2023_autumn/DataScience/Final_Proj/data/cleaned_data.RData")
load("E:/2023_autumn/DataScience/Final_Proj/data/Manhattan_latlonmap.RData")

Overview

transformed_rental_income=
  transformed_rental_income %>%
  separate(boro_block_lot, into = c("borough", "block", "lot"), sep = "-") %>%
  mutate(
  borough = case_when(
    borough == "1" ~ "Manhattan",
    borough == "2" ~ "Bronx",
    borough == "3" ~ "Brooklyn",
    borough == "4" ~ "Queens",
    borough == "5" ~ "Staten Island")
  ) %>% 
  filter(
    borough == "Manhattan"
  )

Manhattan_data = Manhattan_data %>%
  separate(address, into = c("address", "toremove"), sep = ",") %>%
  select(-toremove)

transformed_rental_income = 
  left_join(transformed_rental_income, Manhattan_data, by = "address")
## Columbia university lat lon 40.80754 -73.96257
## Hammer health science building lat lon 40.84252 -73.94243 

for_map =  transformed_rental_income %>% 
  filter(report_year > 2019) %>%
  select(-c(latitude,longitude)) 

income_sqft_M = for_map %>%
  plot_mapbox(
    lon = ~lon,
    lat = ~lat,
    color = ~gross_income_per_sq_ft,
    mode = 'markers',
    alpha = 0.5,
    hovertext = ~gross_income_per_sq_ft,
    hoverinfo = 'text',
    colors = "Spectral"
  ) %>%
  layout(
    mapbox = list(
      style = "streets",
      zoom = 10,
      center = list(lat = 40.81, lon = -73.96)
    )
  )

yearsbuild_M = for_map %>%
  plot_mapbox(
    lon = ~lon,
    lat = ~lat,
    color = ~year_built,
    mode = 'markers',
    alpha = 0.5,
    hovertext = ~year_built,
    hoverinfo = 'text',
    colors = c('red','yellow','green')
  ) %>%
  layout(
    mapbox = list(
      style = "streets",
      zoom = 10,
      center = list(lat = 40.81, lon = -73.96)
    )
  )

elevator_M = for_map %>%
  plot_mapbox(
    lon = ~lon,
    lat = ~lat,
    color = ~building_classification,
    mode = 'markers',
    alpha = 1,
    hovertext = ~building_classification,
    hoverinfo = 'text'
  ) %>%
  layout(
    mapbox = list(
      style = "streets",
      zoom = 10,
      center = list(lat = 40.81, lon = -73.96)
    )
  )


subplot(income_sqft_M, yearsbuild_M,elevator_M, nrows = 1, margin = 0.01) %>% layout(showlegend = FALSE, title = 'Income/sqft - Year built - Classification')
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
income_sqft_M
yearsbuild_M
elevator_M
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

text here

For Columbia Students

what about the price in Columbia university and Columbia university Irving medical center?

latCU = 40.80754
lonCU = -73.96257
latCUIMC = 40.84252
lonCUIMC = -73.94243

near_columbia = for_map %>%
  filter(
    lat >  latCU - 0.01,
    lat < latCU + 0.01,
    lon > lonCU -0.005,
    lon < lonCU + 0.005
    ) %>%
  plot_mapbox(
    lon = ~lon,
    lat = ~lat,
    color = ~gross_income_per_sq_ft,
    mode = 'markers',
    alpha = 1,
    hovertext = ~address,
    text = ~gross_income_per_sq_ft,
    meta = ~building_classification,
    hovertemplate = "%{hovertext} <br> %{meta} <br>gross_income_per_sq_ft: %{text}",
    hoverinfo = 'text',
    colors = "Spectral"
  )  %>%
  layout(
    mapbox = list(
      style = "streets",
      zoom = 13,
      center = list(lat = latCU, lon = lonCU)
    )
  )


near_CUIMC = for_map %>% 
  filter(
    lat >  latCUIMC - 0.01,
    lat < latCUIMC + 0.01,
    lon > lonCUIMC -0.005,
    lon < lonCUIMC + 0.005    
  )%>%
  plot_mapbox(
    lon = ~lon,
    lat = ~lat,
    color = ~gross_income_per_sq_ft,
    mode = 'markers',
    alpha = 1,
    hovertext = ~address,
    text = ~gross_income_per_sq_ft,
    meta = ~building_classification,
    hovertemplate = "%{hovertext} <br> %{meta} <br>gross_income_per_sq_ft: %{text}",
    hoverinfo = 'text',
    colors = "Spectral"
  ) %>%
  layout(
    mapbox = list(
      style = "streets",
      zoom = 13,
      center = list(lat = latCUIMC, lon = lonCUIMC)
    )
  )

subplot(near_columbia, near_CUIMC, nrows = 1, titleY = TRUE, titleX = TRUE, margin = 0.01)